//
//  MonitorInfoThirdView.m
//  ICrEAM
//
//  Created by kuroro on 16/11/2.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "MonitorInfoThirdView.h"
#import "ICMTitleSubTitleView.h"
#import "ActivityTableViewCell.h"
#import "ServiceActivityTableViewCell.h"

@interface MonitorInfoThirdView()
@property (nonatomic,strong)NSMutableArray *dataSource;
@property (nonatomic,strong)NSMutableArray *serviceDataSource;
@end

@implementation MonitorInfoThirdView

-(NSMutableArray *)dataSource{
    if (!_dataSource) {
        _dataSource = [NSMutableArray array];
    }
    return _dataSource;
}

-(NSMutableArray *)serviceDataSource{
    if (!_serviceDataSource) {
        _serviceDataSource = [NSMutableArray array];
    }
    return _serviceDataSource;
}

- (instancetype)initMonitorInfoThirdViewWithDic:(NSDictionary *)dic{
    if (self = [super init]) {
        __weak typeof(self) weakSelf = self;
        self.backgroundColor = [UIColor whiteColor];
        
        if (IsArr(dic[@"USER_DEFINED_MSG"])) {
            self.dataSource = dic[@"USER_DEFINED_MSG"];
        }
        
        //头部
        UIView *headerView = [[UIView alloc]init];
        
        UILabel *titleLabel = [[UILabel alloc]init];
        titleLabel.font = TitleFont;
        titleLabel.textColor = TitleColor;
        titleLabel.text = @"监控信息";
        [headerView addSubview:titleLabel];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(headerView.mas_centerX);
            make.centerY.equalTo(headerView.mas_centerY);
        }];
        
        UILabel *pageNum = [[UILabel alloc]init];
        pageNum.font = ContentFont;
        pageNum.textColor = ContentTextColor_Gray;
        pageNum.text = @"(3/3)";
        [headerView addSubview:pageNum];
        [pageNum mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(titleLabel.mas_bottom);
            make.left.equalTo(titleLabel.mas_right);
        }];
        
        UIView *headerLineView = [[UIView alloc]init];
        headerLineView.backgroundColor = SepColor_gray;
        [headerView addSubview:headerLineView];
        [headerLineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(headerView.mas_left).offset(3);
            make.right.equalTo(headerView.mas_right).offset(-3);
            make.bottom.equalTo(headerView.mas_bottom);
            make.height.equalTo(@(1));
        }];
        
        [self addSubview:headerView];
        [headerView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.mas_top);
            make.left.equalTo(weakSelf.mas_left);
            make.right.equalTo(weakSelf.mas_right);
            make.height.equalTo(@(ActualHeight(65)));
        }];
        
        //信息
        UIView *infoView = [[UIView alloc]init];
        infoView.backgroundColor = BackgroundColor_White;
        
        UIView * returnVisit  = [ICMTitleSubTitleView createICMTitleSubTitleViewWithTitle:@"是否接受回访" subtitle:dic[@"IS_ACCEPT_VISIT"]?:@""];
        [infoView addSubview:returnVisit];
        [returnVisit mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(infoView.mas_left).offset(ActualWidth(60));
            make.centerY.equalTo(infoView.mas_centerY);
            make.height.equalTo(@(ActualHeight(65)));
            make.width.equalTo(@(ActualWidth(145)));
        }];
        
        UIView *result = [ICMTitleSubTitleView createICMTitleSubTitleViewWithTitle:@"回访结果" subtitle:dic[@"VISIT_RESULT"]?:@""];
        [infoView addSubview:result];
        [result mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(returnVisit.mas_right).offset(8);
            make.centerY.equalTo(infoView.mas_centerY);
            make.height.equalTo(@(ActualHeight(65)));
            make.width.equalTo(@(ActualWidth(145)));
        }];
        
        double money = [dic[@"ARREARAGE_AMOUNT"] doubleValue];
        UIView *Arrear = [ICMTitleSubTitleView createICMTitleSubTitleViewWithTitle:@"欠款金额" subtitle:[NSString stringWithFormat:@"%.1f",money]];
        [infoView addSubview:Arrear];
        [Arrear mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(result.mas_right).offset(8);
            make.centerY.equalTo(infoView.mas_centerY);
            make.height.equalTo(@(ActualHeight(65)));
            make.width.equalTo(@(ActualWidth(145)));
        }];
        
        UIView *infoLine = [[UIView alloc]init];
        infoLine.backgroundColor = SepColor_gray;
        [infoView addSubview:infoLine];
        [infoLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(infoView.mas_bottom);
            make.left.equalTo(infoView.mas_left).offset(3);
            make.right.equalTo(infoView.mas_right).offset(-3);
            make.height.equalTo(@(1));
        }];
        
        [self addSubview:infoView];
        [infoView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(headerView.mas_bottom);
            make.left.equalTo(weakSelf.mas_left);
            make.right.equalTo(weakSelf.mas_right);
            make.height.equalTo(@(ActualHeight(115)));
        }];
        
        
        //抱怨
        UIView *grumble = [[UIView alloc]init];
        grumble.backgroundColor = BackgroundColor_White;
        
        UILabel *grumbleLabel = [[UILabel alloc]init];
        grumbleLabel.font = NaviFont;
        grumbleLabel.textColor = TitleColor_Dark;
        grumbleLabel.text = @"客户抱怨";
        [grumble addSubview:grumbleLabel];
        [grumbleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(grumble.mas_left).offset(ActualWidth(60));
            make.top.equalTo(grumble.mas_top).offset(ActualHeight(15));
        }];
        
        UILabel *textLabel = [[UILabel alloc]init];
        textLabel.font = TitleFont;
        textLabel.layer.borderColor = TextFeildBackgroundColor_Gray.CGColor;
        textLabel.layer.borderWidth = 1;
        textLabel.text = !StrIsZero_gdm(dic[@"COMPLAIN_REMARK"])?dic[@"COMPLAIN_REMARK"]:@"";
        textLabel.backgroundColor = [UIColor whiteColor];
        textLabel.textAlignment = NSTextAlignmentLeft;
        textLabel.numberOfLines = 0;
        textLabel.textColor = ContentTextColor_Black;
        [grumble addSubview:textLabel];
        [textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(grumbleLabel.mas_bottom).offset(15);
            make.centerX.equalTo(grumble.mas_centerX);
            make.height.equalTo(@(ActualHeight(65)));
            make.width.equalTo(@(ActualWidth(760)));
        }];
        
        UIView *grumbleLine = [[UIView alloc]init];
        grumbleLine.backgroundColor = SepColor_gray;
        [grumble addSubview:grumbleLine];
        [grumbleLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(grumble.mas_bottom);
            make.left.equalTo(grumble.mas_left).offset(3);
            make.right.equalTo(grumble.mas_right).offset(-3);
            make.height.equalTo(@(1));
        }];
        
        [self addSubview:grumble];
        [grumble mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(infoView.mas_bottom);
            make.left.equalTo(weakSelf.mas_left);
            make.right.equalTo(weakSelf.mas_right);
            make.height.equalTo(@(ActualHeight(125)));
        }];
        
        //提示
        UIView *prompt = [[UIView alloc]init];
        prompt.backgroundColor = BackgroundColor_White;
        
        UILabel *promptLabel = [[UILabel alloc]init];
        promptLabel.font = NaviFont;
        promptLabel.textColor = TitleColor_Dark;
        promptLabel.text = @"自定义提示信息";
        [prompt addSubview:promptLabel];
        [promptLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(prompt.mas_left).offset(ActualWidth(60));
            make.top.equalTo(prompt.mas_top).offset(ActualHeight(50));
        }];
        
        self.promptTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
        self.promptTableView.delegate = self;
        self.promptTableView.dataSource = self;
        self.promptTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        self.promptTableView.backgroundColor = BackgroundColor_White;
        [self.promptTableView registerClass:[ActivityTableViewCell class] forCellReuseIdentifier:@"ActivityTableViewCell"];
        [prompt addSubview:self.promptTableView];
        [self.promptTableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(promptLabel.mas_bottom).offset(15);
            make.centerX.equalTo(prompt.mas_centerX);
            make.width.equalTo(@(ActualWidth(760)));
            make.height.equalTo(@(ActualHeight(120)));
        }];
        
        UIView *promptLine = [[UIView alloc]init];
        promptLine.backgroundColor = SepColor_gray;
        [prompt addSubview:promptLine];
        [promptLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(prompt.mas_bottom);
            make.left.equalTo(prompt.mas_left).offset(3);
            make.right.equalTo(prompt.mas_right).offset(-3);
            make.height.equalTo(@(1));
        }];
        
        
        [self addSubview:prompt];
        [prompt mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(grumble.mas_bottom);
            make.left.equalTo(weakSelf.mas_left);
            make.right.equalTo(weakSelf.mas_right);
            make.height.equalTo(@(ActualHeight(210)));
        }];
        
        //底部
        UIView *bottomView = [[UIView alloc]init];
        bottomView.backgroundColor = BackgroundColor_White;
        if (IsArr(dic[@"TT_TECH_ACTIVITY"]) && !IsArrEmpty(dic[@"TT_TECH_ACTIVITY"])){
            self.serviceDataSource = dic[@"TT_TECH_ACTIVITY"];
            self.serviceTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
            self.serviceTableView.delegate = self;
            self.serviceTableView.dataSource = self;
            self.serviceTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
            self.serviceTableView.backgroundColor = BackgroundColor_White;
            [self.serviceTableView registerNib:[UINib nibWithNibName:@"ServiceActivityTableViewCell" bundle:nil] forCellReuseIdentifier:@"ServiceActivityTableViewCell"];
            [bottomView addSubview:self.serviceTableView];
            [self.serviceTableView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(bottomView.mas_centerY);
                make.centerX.equalTo(bottomView.mas_centerX);
                make.width.equalTo(@(ActualWidth(760)));
                make.height.equalTo(@(ActualHeight(75)));
            }];
            [self addSubview:bottomView];
            [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(prompt.mas_bottom);
                make.left.equalTo(weakSelf.mas_left);
                make.right.equalTo(weakSelf.mas_right);
                make.bottom.equalTo(weakSelf.mas_bottom);
            }];
        }
    }
    return self;
}

+ (instancetype)creatMonitorInfoThirdViewWithDic:(NSDictionary *)dic{
    return [[MonitorInfoThirdView alloc]initMonitorInfoThirdViewWithDic:dic];
    
}

-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (tableView == self.serviceTableView) {
        return self.serviceDataSource.count;
    }else{
        return self.dataSource.count;
    }
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView == self.serviceTableView) {
        ServiceActivityTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ServiceActivityTableViewCell" forIndexPath:indexPath];
//        cell.redStar.hidden = [self.serviceDataSource[indexPath.row][@"IS_VISIBLE"] isEqualToString:@"12781001"]?NO:YES;
        cell.titleString.text = !StrIsZero_gdm(self.serviceDataSource[indexPath.row][@"TECH_ACTI_NAME"])?self.serviceDataSource[indexPath.row][@"TECH_ACTI_NAME"]:@"";
        cell.titleString.hidden = [self.serviceDataSource[indexPath.row][@"IS_VISIBLE"] isEqualToString:@"12781001"]?NO:YES;
        return cell;
    }else{
    ActivityTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ActivityTableViewCell"];
    [cell SetUpHeaderViewWithString:self.dataSource[indexPath.row]];
    return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.serviceTableView) {
        return ActualHeight(25);
    }
    return ActualHeight(40);
}


@end
